package com.study.shengsiyuan.example03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

public class MyChatClient {
	public static void main(String[] args) {
		EventLoopGroup Group = new NioEventLoopGroup();
		try {
			Bootstrap sb = new Bootstrap();
			sb.group(Group).channel(NioSocketChannel.class)
				.handler(new MyChatClientInitializer());
			ChannelFuture cf = sb.connect("localhost",8899).sync();
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			for(; ;) {//不停的在读取console 数据
				cf.channel().writeAndFlush(br.readLine()+"\r\n");
			}

		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			Group.shutdownGracefully();

		}
	}
}
